package org.xiaoyu.txy.live.model.service;

import org.xiaoyu.txy.live.LiveCodeConstant;
import org.xiaoyu.txy.live.model.message.req.LiveChannelSetStatus;
import org.xiaoyu.txy.live.model.message.req.LiveTapeStart;
import org.xiaoyu.txy.live.model.message.req.LiveTapeStop;
import org.xiaoyu.txy.live.model.message.res.ResLiveChannelSetStatus;
import org.xiaoyu.txy.live.model.message.res.ResLiveTapeStart;
import org.xiaoyu.txy.live.model.message.res.ResLiveTapeStop;
import org.xiaoyu.txy.live.util.HttpClientUtil;
import org.xiaoyu.txy.live.util.LiveCodeUtil;

import com.alibaba.fastjson.JSON;

/**
 * 提供腾讯云直播码服务功能
 * @author 张晓宇
 *
 */
public class LiveCodeService {

	/**
	 * 对一条直播流执行禁用、断流和允许推流操作
	 * @param channelSetStatus
	 * @return
	 */
	public static ResLiveChannelSetStatus liveChannelSetStatus(LiveChannelSetStatus channelSetStatus) {
		String url = createUrl(channelSetStatus, LiveCodeConstant.FCGI_REQUEST_URL);
		String result = HttpClientUtil.doGet(url);
		return JSON.parseObject(result, ResLiveChannelSetStatus.class);
	}
	
	/**
	 * 创建录制任务
	 * @param liveTapeStart
	 * @return
	 */
	public static ResLiveTapeStart liveTapeStart(LiveTapeStart liveTapeStart) {
		String url = createUrl(liveTapeStart, LiveCodeConstant.FCGI_REQUEST_URL);
		String result = HttpClientUtil.doGet(url);
		return JSON.parseObject(result, ResLiveTapeStart.class);
	}
	
	
	/**
	 * 结束录制任务
	 * @param liveTapeStop
	 * @return
	 */
	public static ResLiveTapeStop liveTapeStop(LiveTapeStop liveTapeStop) {
		String url = createUrl(liveTapeStop, LiveCodeConstant.FCGI_REQUEST_URL);
		String result = HttpClientUtil.doGet(url);
		return JSON.parseObject(result, ResLiveTapeStop.class);
	}
	
	private static String createUrl (Object parms, String url) {
		Object p = JSON.toJSON(parms);
		return LiveCodeUtil.getFullLink(url, p);	
	}
}
